package main

import (
	"fmt"
	"lhy.org/custom_system/service"
)

func inputInfo(f func() error) {
	err := f()
	for {
		if err != nil {
			fmt.Println(err.Error(), "请重新输入")
			err = f()
		} else {
			break
		}
	}
}

func main() {
	for {
		service.ShowMenu()
	label:
		key, err := service.InputMenu()
		for {
			if err != nil || key < 1 || key > 5 {
				fmt.Println("输入错误，请重新输入")
				key, err = service.InputMenu()
			}
			break
		}
		switch key {
		case 1:
			fmt.Println("添加用户")
			inputInfo(service.AddCustom)
		case 2:
			fmt.Println("更新用户")
			inputInfo(service.UpdateCustom)
		case 3:
			fmt.Println("删除用户")
			inputInfo(service.DeleteCustom)
		case 4:
			service.ShowAllCustom()
		}
		continue label
	}

}
